import com.alibaba.fastjson.JSON;
import com.documents4j.api.DocumentType;
import com.documents4j.api.IConverter;
import com.documents4j.job.LocalConverter;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.jeecg.modules.lab.util.QrCodeImage;
import org.junit.Test;

import java.io.*;

import static org.jeecg.modules.lab.util.QrCodeImage.generatorQrCode;

public class test {
    @Test
    public void test() {
        String qrCodePath = "https://www.baidu.com";
        String qrCodeLocalPath = "D:\\zhuiExperiment\\测试二维码图片.png";
        try {
            generatorQrCode(qrCodePath, qrCodeLocalPath);
        } catch (Exception e) {
            System.out.println(JSON.toJSON(e));
        }
    }
    @Test
    public void test23() throws IOException, InvalidFormatException {
        String qrCodeLocalPath = "D:\\zhuiExperiment\\测试二维码图片.png";
        String qrCodeLocalPath2 = "D:\\zhuiExperiment\\测试二维码图片.docx";
        QrCodeImage.amgWord(qrCodeLocalPath,qrCodeLocalPath2);
    }
    @Test
    public void test2() throws IOException {
        String wordFile = "D:\\zhuiExperiment\\downloadPath\\水处理用油田化学剂 杀菌剂CT10-4消泡剂.docx";
        String pdfFile = "D:\\zhuiExperiment\\downloadPath\\水处理用油田化学剂 杀菌剂CT10-4消泡剂.pdf";
        System.out.println("开始转换...");
        InputStream docxInputStream = null;
        OutputStream outputStream = null;
        try {
            // 原word地址
            docxInputStream = new FileInputStream(wordFile);
            // 转换后pdf生成地址
            outputStream = new FileOutputStream(pdfFile);
            IConverter converter = LocalConverter.builder().build();
            converter.convert(docxInputStream)
                    .as(DocumentType.DOCX)
                    .to(outputStream)
                    .as(DocumentType.PDF).execute();
            // 关闭
            converter.shutDown();
            // 关闭
            outputStream.close();
            // 关闭
            docxInputStream.close();
        } catch (Exception e) {
            System.out.println("[documents4J] word转pdf失败:" + e.toString());
        } finally {
            if (outputStream != null) {
                outputStream.close();
            }
            if (docxInputStream != null) {
                docxInputStream.close();
            }
        }
    }
}
